import { get, post, put, del } from '@/utils/request';

// 定义接口类型
export interface TeamInfo {
  id: number;
  name: string;
  description: string;
  leader: {
    id: number;
    username: string;
    realName: string;
    avatar: string;
  };
  members: Array<{
    id: number;
    username: string;
    realName: string;
    avatar: string;
    roles: string[];
  }>;
  createTime: string;
  updateTime: string;
}

export interface TeamParams {
  name: string;
  description?: string;
  leaderId: number;
  memberIds?: number[];
}

// 获取团队列表
export function getTeamList(params?: any) {
  return get<{
    total: number;
    list: TeamInfo[];
  }>('/team/list', params);
}

// 获取团队详情
export function getTeamDetail(id: number) {
  return get<TeamInfo>(`/team/${id}`);
}

// 创建团队
export function createTeam(data: TeamParams) {
  return post<number>('/team/create', data);
}

// 更新团队
export function updateTeam(id: number, data: Partial<TeamParams>) {
  return put<boolean>(`/team/${id}`, data);
}

// 删除团队
export function deleteTeam(id: number) {
  return del<boolean>(`/team/${id}`);
}

// 添加团队成员
export function addTeamMember(teamId: number, userId: number, roles?: string[]) {
  return post(`/team/${teamId}/member`, { userId, roles });
}

// 移除团队成员
export function removeTeamMember(teamId: number, userId: number) {
  return del(`/team/${teamId}/member/${userId}`);
}

// 更新团队成员角色
export function updateTeamMemberRoles(teamId: number, userId: number, roles: string[]) {
  return put(`/team/${teamId}/member/${userId}/roles`, { roles });
}

// 获取我的团队
export function getMyTeams() {
  return get<TeamInfo[]>('/team/my-teams');
} 